package ylsb.service;


import org.springframework.stereotype.Service;
import ylsb.dao.YltpRenyuanfenpeiMapper;
import ylsb.model.HaocaiyinjinExample;
import ylsb.model.YltpRenyuanfenpei;
import ylsb.model.YltpRenyuanfenpeiExample;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class YltprenyuanfenpeiService {

    @Resource
    YltpRenyuanfenpeiMapper ddMapper;

    public Integer getSubmitedCount(String ppxianmguId){
        YltpRenyuanfenpeiExample mmExample=new YltpRenyuanfenpeiExample();
        YltpRenyuanfenpeiExample.Criteria criteria = mmExample.createCriteria();
        criteria.andXiangmuidEqualTo(ppxianmguId).andIssubmitEqualTo(1);
        return ddMapper.selectByExample(mmExample)==null?0:ddMapper.selectByExample(mmExample).size();
    }

    public List<Map<String, Object>> findRenyuanFenpeiByXiangmuId(String mmxiangmuId){
        return ddMapper.findRenyuanFenpeiByXiangmuId(mmxiangmuId);
    }

    public boolean add(YltpRenyuanfenpei ppYltpRenyuanfenpei){
        return ddMapper.insert(ppYltpRenyuanfenpei)==1;
    }

    public boolean update(YltpRenyuanfenpei ppYltpRenyuanfenpei){
        return ddMapper.updateByPrimaryKey(ppYltpRenyuanfenpei)==1;
    }
    public boolean updateByPrimaryKeySelective(YltpRenyuanfenpei ppYltpRenyuanfenpei){
        return ddMapper.updateByPrimaryKeySelective(ppYltpRenyuanfenpei)==1;
    }

    public boolean delete(String ppId){
        return ddMapper.deleteByPrimaryKey(ppId)>=0;
    }

    public Integer deleteByxiangmuId(String mmxiangmuId){
        YltpRenyuanfenpeiExample mmExample=new YltpRenyuanfenpeiExample();
        YltpRenyuanfenpeiExample.Criteria criteria = mmExample.createCriteria();
        criteria.andXiangmuidEqualTo(mmxiangmuId);
        return ddMapper.deleteByExample(mmExample);
    }

    public List<YltpRenyuanfenpei>  findbyUserIDandXiangmuId(String ppuserId,String ppxianmguId){
        YltpRenyuanfenpeiExample mmExample=new YltpRenyuanfenpeiExample();
        YltpRenyuanfenpeiExample.Criteria criteria = mmExample.createCriteria();
        criteria.andUseridEqualTo(ppuserId).andXiangmuidEqualTo(ppxianmguId);
        return ddMapper.selectByExample(mmExample);
    }
    public List<YltpRenyuanfenpei>  findUserNumberByXiangmuId(String ppxianmguId){
        YltpRenyuanfenpeiExample mmExample=new YltpRenyuanfenpeiExample();
        YltpRenyuanfenpeiExample.Criteria criteria = mmExample.createCriteria();
        criteria.andXiangmuidEqualTo(ppxianmguId);
        return ddMapper.selectByExample(mmExample);
    }

    public List<YltpRenyuanfenpei> findUserByXiangmuId(String ppxianmguId){
        YltpRenyuanfenpeiExample mmExample=new YltpRenyuanfenpeiExample();
        YltpRenyuanfenpeiExample.Criteria criteria = mmExample.createCriteria();
        criteria.andXiangmuidEqualTo(ppxianmguId);
        return ddMapper.selectByExample(mmExample);
    }
    public boolean isexistByxiangmuId(String xiangmuId){
        YltpRenyuanfenpeiExample mmExample=new YltpRenyuanfenpeiExample();
        YltpRenyuanfenpeiExample.Criteria criteria=mmExample.createCriteria();
        criteria.andXiangmuidEqualTo(xiangmuId);
        return  ddMapper.selectByExample(mmExample).size()>0;
    }


}
